package com.sh.rbac.core.storage.config;

import com.sh.rbac.core.common.exception.CustomException;
import com.sh.rbac.core.common.result.ResultCodeEnum;
import com.sh.rbac.domain.entity.FileConfig;
import com.sh.rbac.service.FileConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author wb
 * @since 2025-10-14
 */

@Component
public class StorageFactory {

    @Autowired
    private FileConfigService fileConfigService;

    public OssClient getInstance() {
        FileConfig fileConfig = fileConfigService.getDefaultConfig();
        if (fileConfig == null) {
            throw new CustomException(ResultCodeEnum.STORAGE_NOT_CONFIG);
        }
        return new OssClient(fileConfig);
    }
}
